﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CategorySelect.aspx.cs" Inherits="Bingosoft.WebApp.Modules.SecurityConsole.Common.FunctionControl.CategorySelect.CategorySelect" %>
<%@ Import Namespace="Bingosoft.Modules.SecurityConsole.Common.Helper" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
    var Global = {};
    Global.contextPath = '<%= RequestHelper.GetContextPath(Request) %>';
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>分类选择信息</title>
        <base target="_self" />
        <web:Script ID="Script1" src="~/Scripts/jquery.js" runat="server" />
        <web:Script ID="Script2" src="~/Scripts/jquery.utils.js" runat="server" />
        <web:Script ID="Script3" src="~/Scripts/jquery_plugins/jquery.json.js" runat="server" />
        <web:Script ID="Script8" src="~/Widgets/core/tree/ui.tree.js" runat="server" />
        
        <link rel="stylesheet" type="text/css" href="~/Widgets/core/tree/ui.tree.css"/>
		
	</head>
    	<script type="text/javascript">
    	    /***
    	    使用方法
    	    process( {
    	    idField:
    	    nameField:
    	    title:
    	    sqlId:  //可以是字符串"sqlId"和js数组["sqlId1","sqlId2"]
    	    params:
    	    isAsyn: //取值"true"|"false"
    	    dataProvider:(可选)
    	    } ) ;
			
    	    function process(params){
    	    var idField = params.idField ;
    	    var nameField = params.nameField ;
    	    var selectedId = document.getElementById(idField).value ;
    	    var selectedText = document.getElementById(nameField).value ;
			
    	    var returnValue = showCenterModalDialog(path + '/modules/common/clz_select.jsp',700,550,
    	    { 
    	    title:params.title,
    	    sqlId:params.sqlId,
    	    selectedId:selectedId,
    	    selectedText:selectedText,
    	    params:params.params,
    	    isAsyn:params.isAsyn,
    	    dataProvider:params.dataProvider
    	    }
    	    ) ;
				
    	    if(!returnValue) return ;
				
    	    var idField = params.idField ;
    	    var nameField = params.nameField ;
				
    	    document.getElementById(idField).value = returnValue.id;
    	    document.getElementById(nameField).value = returnValue.text;
    	    }
    	    ***/


    	    var path = Global.contextPath;
    	    var args = window.dialogArguments;
    	    var sqlId = args.sqlId;
    	    var childSqlId = args.childSqlId;
    	    var title = args.title || '分类选择';
    	    var _name = title.replace("选择", "");
    	    var params = args.params || {};
    	    var selectedId = args.selectedId;
    	    var selectedText = args.selectedText;
    	    var forbiddenIds = args.forbiddenIds || null;
    	    var result = null;
    	    var dataProvider = args.dataProvider || '';
    	    var isAsyn = args.isAsyn || 'false';
    	    var daoBeanName = args.daoBeanName;
    	    /*初始化树*/
    	    $(function () {
    	        var service_params = {};

    	        service_params["parentId"] = 'root';

    	        if (dataProvider) {
    	            service_params["treeProvider"] = dataProvider;
    	        }
    	        else {
    	            if (daoBeanName) {
    	                service_params["daoBeanName"] = daoBeanName;
    	            }
    	            service_params["sqlId"] = sqlId;
    	            if (childSqlId) {
    	                service_params["childSqlId"] = childSqlId;
    	            }
    	        }

    	        jQuery.extend(service_params, params);
    	        $('#treeDiv').tree({//tree为容器ID
    	            asyn: isAsyn, //异步
    	            rootId: 'root',
    	            rootText: title,
    	            CommandName: 'java.tree.command',
    	            onNodeClick: leftClick,
    	            params: service_params,
    	            onLoaded: function () {
    	                TreeLoadAfter();
    	            }
    	        });
    	        $('#treeDiv').tree().expandLevel(null, 2);
    	        window.document.title = title;
    	        h1Title.innerHTML = title;
    	        yName.innerHTML = _name;
    	    });

    	    function leftClick(id, name, record, currentNode) {
    	        if (!id || id == 'root') return;
    	        var cancheck = record["CANCHECK"];
    	        if (cancheck == 'true' || typeof (cancheck) == 'undefined') {
    	            result = result || {};
    	            result.id = id;
    	            result.text = name;
    	            result.detail = record;
    	            window.returnValue = result;
    	            addContent(name, true);
    	        }
    	    }

    	    function addContent(text, flag) {
    	        if (flag) {
    	            $(document.getElementById('titleId')).attr("title", text);
    	            $("#content").html("<b>" + text + "</b>");
    	            $("#imgTd").html("<img onclick='clearResult()' style='padding-left:30px;cursor:pointer;' src='../../../../../Images/ico_close_win.gif' alt='清除'/>");
    	        } else {
    	            $("#content").html("")
    	            $("#imgTd").html("");
    	        }
    	    }

    	    function clearResult() {
    	        result = { id: '', text: '' };
    	        addContent('', false);
    	        window.returnValue = result;
    	    }

    	    function checkAction(value, text, checked, json, node) {
    	        if (checked) {
    	            result = result || {};
    	            result.id = value;
    	            result.text = text;
    	            result.detail = json;
    	            window.returnValue = result;
    	        }
    	    }

    	    function closeWin() {
    	        window.returnValue = null;
    	        window.close();
    	    }

    	    function confirmSelect() {
    	        if (!result && !selectedId) {
    	            if (window.confirm("您还没有选择" + _name + ",您确定不选择吗?")) {
    	                window.close();
    	            }
    	        } else {
    	            //用户点击了确定按钮操作
    	            result.isConfirm = true;
    	            window.close();
    	        }
    	    }

    	    function getNodeById(root, id) {
    	        try {
    	            var childs = root.childNodes;
    	            if (childs && childs.length > 0) {
    	                for (var i = 0; i < childs.length; i++) {
    	                    var child = childs[i];
    	                    if (child.value == id) {
    	                        return child;
    	                    } else {
    	                        var result = getNodeById(child, id);
    	                        if (result) {
    	                            return result;
    	                        }
    	                    }
    	                }
    	            }

    	            return null;
    	        } catch (e) {
    	            return null;
    	        }
    	    }

    	    TreeLoadAfter = function () {
    	        if (selectedId && selectedText) {
    	            addContent(selectedText, true);
    	            result = result || {};
    	            result.id = selectedId;
    	            result.text = selectedText;
    	            window.returnValue = result;
    	        }
    	        /*
    	        else  if(selectedId){
    	        var node = getNodeById(dyntree_clz.dynTreeRoot,selectedId) ;
    	        if(!node) return ;
    	        addContent(node.text,true) ;
    	        result = result||{} ;
    	        result.id = node.value ;
    	        result.text = node.text ;
    	        window.returnValue = result ;
    	        }
    	        */
    	    }
		</script>
	<body >
    <div id="dialog">
    <form id="form1" runat="server">
		<!-- 页面标题开始 -->
		<div class="header">
			<h1 id="h1Title">
				分类选择
			</h1>
		</div>
		<!--页面标题结束-->
		<div class="content">
			<div class="main" id="treeDiv" oncontextmenu="return false;"
					style="width: 100%; padding: 5px; overflow-y: auto; height:330px">
			</div>
			<hr style="width: 100%;padding: 0px;margin: 0px;"/>
			<div>
				<table width="450px">
					<tr>
						<td><div style="width:400px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; WORD-BREAK: keep-all;" id="titleId"><nobr>已选择<span id="yName"></span>：<span id="content"></span></nobr></div> </td>
						<td id="imgTd"></td>
					</tr>
					
				</table>
			</div>
		</div>
		
        <div class="footer">
		<asp:Button ID="Button1" runat="server" Text="确定"  OnClientClick="return confirmSelect();"/>        
        <asp:Button ID="CloseButton2" runat="server" Text="关闭" OnClientClick="return closeWin();" />        
	</div>
    </form>
        </div>
	</body>
</html>
